//
//  JBHomeTitleView.m
//  OCsinaBlog
//
//  Created by jobo on 16/4/26.
//  Copyright © 2016年 jobo. All rights reserved.
//

#import "JBHomeTitleView.h"

@implementation JBHomeTitleView

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame])
    {
        //设置按钮背景
        [self setBackgroundImage:[UIImage imageNamed:@"timeline_card_bottom_line_highlighted"] forState:UIControlStateHighlighted];
        
       
        
        //设置图片
        [self setImage:[UIImage imageNamed:@"new_dot"] forState:UIControlStateNormal];
        
        //设置字体颜色
        [self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        //设置文字大小
        self.titleLabel.font = [UIFont systemFontOfSize:14];
    
        //设置图片不拉升
        self.imageView.contentMode = UIViewContentModeCenter ;
        //设置文字居中
        self.titleLabel.textAlignment = NSTextAlignmentCenter ;
        
        //设置背景图片圆角
        self.layer.cornerRadius = 5 ;
        self.layer.masksToBounds = YES;
    
    }
    
    return self ;
}

#define imgWidth 10 //图片的宽
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    
    //重新设置按钮的宽度
    
    
    
    
    //重新布局文字跟图片
    
    //新布局图片的frame值
    CGFloat imgX = self.bounds.size.width - imgWidth ;
    CGFloat imgY = self.bounds.size.height / 2 - 5 ;
    CGFloat imgW = imgWidth ;
    CGFloat imgH = 10;
    self.imageView.frame = CGRectMake(imgX, imgY, imgW, imgH) ;
    
    //新布局的位子frame值
    CGFloat titleX = 0 ;
    CGFloat titleY = 0 ;
    CGFloat titleW = self.bounds.size.width - imgWidth ;
    CGFloat titleH = self.bounds.size.height ;
    self.titleLabel.frame = CGRectMake(titleX, titleY, titleW, titleH);
    

}


@end
